import joystick from "./joystick";

export default class start extends Laya.Script {
    /** @prop {name:joy_stick,tips:"触摸中心点",type:Node,default:null } */
    joy_stick:Laya.Node = null;

    /** @prop {name:player,tips:"触摸中心点",type:Node,default:null } */
    player:Laya.Node = null;

    /** @prop {name:speed,tips:"触摸中心点",type:number,default:20 } */
    speed:number = 20;

    constructor() { super(); }
    private joy_stick_node = null;
    

    onAwake(): void {
        this.joy_stick_node = this.joy_stick.getComponent(joystick);        
    }

    onEnable(): void {
       
    }

    onDisable(): void {
    }

    onUpdate(){
        var dt = Laya.timer.delta / 1000;
       
        if (this.joy_stick_node.dir.x === 0 && this.joy_stick_node.dir.y === 0) {
            return;
        }
        console.log('this.joy_stick_node.dir.x',this.joy_stick_node.dir.x,this.joy_stick_node.dir.y);
        var vx: number = this.speed * this.joy_stick_node.dir.x; 
        var vy: number = this.speed * this.joy_stick_node.dir.y; 
        console.log('vx,vy',vx,vy,this.speed);
        var dt = Laya.timer.delta / 1000;

        var item_sprite: Laya.Sprite = this.player as Laya.Sprite;
        item_sprite.x += (vx * dt);
        item_sprite.y += (vy * dt);
        console.log(item_sprite.x,item_sprite.y);
       
    }
}